// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Requests;
using Elastic.Clients.Elasticsearch.Serialization;
using Elastic.Transport;
using Elastic.Transport.Extensions;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.MachineLearning;

public sealed partial class GetOverallBucketsRequestParameters : RequestParameters
{
}

/// <summary>
/// <para>
/// Get overall bucket results.
/// </para>
/// <para>
/// Retrievs overall bucket results that summarize the bucket results of
/// multiple anomaly detection jobs.
/// </para>
/// <para>
/// The <c>overall_score</c> is calculated by combining the scores of all the
/// buckets within the overall bucket span. First, the maximum
/// <c>anomaly_score</c> per anomaly detection job in the overall bucket is
/// calculated. Then the <c>top_n</c> of those scores are averaged to result in
/// the <c>overall_score</c>. This means that you can fine-tune the
/// <c>overall_score</c> so that it is more or less sensitive to the number of
/// jobs that detect an anomaly at the same time. For example, if you set
/// <c>top_n</c> to <c>1</c>, the <c>overall_score</c> is the maximum bucket score in the
/// overall bucket. Alternatively, if you set <c>top_n</c> to the number of jobs,
/// the <c>overall_score</c> is high only when all jobs detect anomalies in that
/// overall bucket. If you set the <c>bucket_span</c> parameter (to a value
/// greater than its default), the <c>overall_score</c> is the maximum
/// <c>overall_score</c> of the overall buckets that have a span equal to the
/// jobs' largest bucket span.
/// </para>
/// </summary>
public sealed partial class GetOverallBucketsRequest : PlainRequest<GetOverallBucketsRequestParameters>
{
	public GetOverallBucketsRequest(Elastic.Clients.Elasticsearch.Id jobId) : base(r => r.Required("job_id", jobId))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.MachineLearningGetOverallBuckets;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ml.get_overall_buckets";

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>allow_no_match</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("allow_no_match")]
	public bool? AllowNoMatch { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>bucket_span</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("bucket_span")]
	public Elastic.Clients.Elasticsearch.Duration? BucketSpan { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>end</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("end")]
	public DateTimeOffset? End { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>exclude_interim</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("exclude_interim")]
	public bool? ExcludeInterim { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>overall_score</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("overall_score")]
	public object? OverallScore { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>start</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("start")]
	public DateTimeOffset? Start { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>top_n</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("top_n")]
	public int? TopN { get; set; }
}

/// <summary>
/// <para>
/// Get overall bucket results.
/// </para>
/// <para>
/// Retrievs overall bucket results that summarize the bucket results of
/// multiple anomaly detection jobs.
/// </para>
/// <para>
/// The <c>overall_score</c> is calculated by combining the scores of all the
/// buckets within the overall bucket span. First, the maximum
/// <c>anomaly_score</c> per anomaly detection job in the overall bucket is
/// calculated. Then the <c>top_n</c> of those scores are averaged to result in
/// the <c>overall_score</c>. This means that you can fine-tune the
/// <c>overall_score</c> so that it is more or less sensitive to the number of
/// jobs that detect an anomaly at the same time. For example, if you set
/// <c>top_n</c> to <c>1</c>, the <c>overall_score</c> is the maximum bucket score in the
/// overall bucket. Alternatively, if you set <c>top_n</c> to the number of jobs,
/// the <c>overall_score</c> is high only when all jobs detect anomalies in that
/// overall bucket. If you set the <c>bucket_span</c> parameter (to a value
/// greater than its default), the <c>overall_score</c> is the maximum
/// <c>overall_score</c> of the overall buckets that have a span equal to the
/// jobs' largest bucket span.
/// </para>
/// </summary>
public sealed partial class GetOverallBucketsRequestDescriptor : RequestDescriptor<GetOverallBucketsRequestDescriptor, GetOverallBucketsRequestParameters>
{
	internal GetOverallBucketsRequestDescriptor(Action<GetOverallBucketsRequestDescriptor> configure) => configure.Invoke(this);

	public GetOverallBucketsRequestDescriptor(Elastic.Clients.Elasticsearch.Id jobId) : base(r => r.Required("job_id", jobId))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.MachineLearningGetOverallBuckets;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ml.get_overall_buckets";

	public GetOverallBucketsRequestDescriptor JobId(Elastic.Clients.Elasticsearch.Id jobId)
	{
		RouteValues.Required("job_id", jobId);
		return Self;
	}

	private bool? AllowNoMatchValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? BucketSpanValue { get; set; }
	private DateTimeOffset? EndValue { get; set; }
	private bool? ExcludeInterimValue { get; set; }
	private object? OverallScoreValue { get; set; }
	private DateTimeOffset? StartValue { get; set; }
	private int? TopNValue { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>allow_no_match</c> query parameter.
	/// </para>
	/// </summary>
	public GetOverallBucketsRequestDescriptor AllowNoMatch(bool? allowNoMatch = true)
	{
		AllowNoMatchValue = allowNoMatch;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>bucket_span</c> query parameter.
	/// </para>
	/// </summary>
	public GetOverallBucketsRequestDescriptor BucketSpan(Elastic.Clients.Elasticsearch.Duration? bucketSpan)
	{
		BucketSpanValue = bucketSpan;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>end</c> query parameter.
	/// </para>
	/// </summary>
	public GetOverallBucketsRequestDescriptor End(DateTimeOffset? end)
	{
		EndValue = end;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>exclude_interim</c> query parameter.
	/// </para>
	/// </summary>
	public GetOverallBucketsRequestDescriptor ExcludeInterim(bool? excludeInterim = true)
	{
		ExcludeInterimValue = excludeInterim;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>overall_score</c> query parameter.
	/// </para>
	/// </summary>
	public GetOverallBucketsRequestDescriptor OverallScore(object? overallScore)
	{
		OverallScoreValue = overallScore;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>start</c> query parameter.
	/// </para>
	/// </summary>
	public GetOverallBucketsRequestDescriptor Start(DateTimeOffset? start)
	{
		StartValue = start;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>top_n</c> query parameter.
	/// </para>
	/// </summary>
	public GetOverallBucketsRequestDescriptor TopN(int? topN)
	{
		TopNValue = topN;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (AllowNoMatchValue.HasValue)
		{
			writer.WritePropertyName("allow_no_match");
			writer.WriteBooleanValue(AllowNoMatchValue.Value);
		}

		if (BucketSpanValue is not null)
		{
			writer.WritePropertyName("bucket_span");
			JsonSerializer.Serialize(writer, BucketSpanValue, options);
		}

		if (EndValue is not null)
		{
			writer.WritePropertyName("end");
			JsonSerializer.Serialize(writer, EndValue, options);
		}

		if (ExcludeInterimValue.HasValue)
		{
			writer.WritePropertyName("exclude_interim");
			writer.WriteBooleanValue(ExcludeInterimValue.Value);
		}

		if (OverallScoreValue is not null)
		{
			writer.WritePropertyName("overall_score");
			JsonSerializer.Serialize(writer, OverallScoreValue, options);
		}

		if (StartValue is not null)
		{
			writer.WritePropertyName("start");
			JsonSerializer.Serialize(writer, StartValue, options);
		}

		if (TopNValue.HasValue)
		{
			writer.WritePropertyName("top_n");
			writer.WriteNumberValue(TopNValue.Value);
		}

		writer.WriteEndObject();
	}
}